package top.hg.tool.modules.car.notice;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.hg.tool.common.util.R;

import java.util.List;

/**
 * @Author: skh
 * @Date: 2019/7/30 10:39
 * @Description:
 */
@RestController
@RequestMapping("/car")
@Api(value = "通知管理")
@Slf4j
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @ApiOperation("新增公告通知")
    @PostMapping("/saveNotice")
    public R saveNotice(@RequestBody NoticeEntity noticeEntity) {
        noticeService.saveNotice(noticeEntity);
        return R.success();
    }

    @ApiOperation("获取通知列表")
    @GetMapping("/getNoticeList")
    public R getNoticeList(String type) {
        if (StrUtil.isBlank(type)) {
            throw new RuntimeException("通知类型不能为空");
        }
        List<NoticeEntity> noticeEntityList = noticeService.getNoticeList(type);
        return R.success(noticeEntityList);
    }

    @ApiOperation("清除通知缓存")
    @GetMapping("/clearNoticeCache")
    public R clearNoticeCache() {
        noticeService.clearNoticeCache();
        return R.success();
    }
}
